load('application');

before(loadFollowedMe, {only: ['show', 'edit', 'update', 'destroy']});

action('new', function () {
    this.title = 'New followedme';
    this.followedme = new FollowedMe;
    render();
});

action(function create() {
    FollowedMe.create(req.body.FollowedMe, function (err, followedme) {
        if (err) {
            flash('error', 'FollowedMe can not be created');
            render('new', {
                followedme: followedme,
                title: 'New followedme'
            });
        } else {
            flash('info', 'FollowedMe created');
            redirect(path_to.followedmes());
        }
    });
});

action(function index() {
    this.title = 'FollowedMes index';
    FollowedMe.all(function (err, followedmes) {
        render({
            followedmes: followedmes
        });
    });
});

action(function show() {
    this.title = 'FollowedMe show';
    render();
});

action(function edit() {
    this.title = 'FollowedMe edit';
    render();
});

action(function update() {
    this.followedme.updateAttributes(body.FollowedMe, function (err) {
        if (!err) {
            flash('info', 'FollowedMe updated');
            redirect(path_to.FollowedMe(this.FollowedMe));
        } else {
            flash('error', 'FollowedMe can not be updated');
            this.title = 'Edit followedme details';
            render('edit');
        }
    }.bind(this));
});

action(function destroy() {
    this.followedme.destroy(function (error) {
        if (error) {
            flash('error', 'Can not destroy followedme');
        } else {
            flash('info', 'FollowedMe successfully removed');
        }
        send("'" + path_to.followedmes() + "'");
    });
});

function loadFollowedMe() {
    FollowedMe.find(params.id, function (err, followedme) {
        if (err || !followedme) {
            redirect(path_to.followedmes());
        } else {
            this.followedme = followedme;
            next();
        }
    }.bind(this));
}
